/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-4-17
 */
package code.extract;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import dao.entity.PageEntity;

public class PageClassifier {
	public static final int NORMAL_TYPE = 0;
	public static final int JAVADOC_TYPE = 1;
	public static final int JAVAFILE_TYPE = 2;
	public static final int SPAM_TYPE = 3;
	public static void main(String args[]){
		try {
			String content = FileDealer.getFileContent("C:/Users/ftc/Desktop/index.html");
			System.out.println(isJavaDoc(content));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public static boolean isJavaDoc(String content){
		if (content == null){
			return false;
		}
		String str_pattern = "<!-- Generated by javadoc.*?-->";
		Pattern pattern = Pattern.compile(str_pattern, 
				Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
		Matcher matcher = pattern.matcher(content);
		if (matcher.find()){
			return true;
		}
		return false;
	}
	public static int getPageType(PageEntity page){
		int result = NORMAL_TYPE;
		if (isJavaDoc(page.getContent()) == true){
			return JAVADOC_TYPE;
		}else if (page.getLink().toString().endsWith(".java")){
			return JAVAFILE_TYPE;
		}
		return result;
	}
}
